package com.example.applications.Kotlin

fun main() {

    ifDemo(6)

    grade(80)

    gradeWhen(80)

    forDemo()

}

//if 判断一个数字是否大于5
fun ifDemo(a: Int) {
    if (a > 5) {
        println("大于5")
    }
}

//成绩评级
fun grade(score: Int) {
    if (score >= 90) {
        println("A")
    } else if (score >= 80) {
        println("B")
    } else if (score >= 70) {
        println("C")
    } else if (score >= 60) {
        println("D")
    } else {
        println("E")
    }
}

//使用when进行成绩评级
fun gradeWhen(score: Int) {
    when (score) {
        in 90..100 -> println("A")
        in 80..89 -> println("B")
        in 70..79 -> println("C")
        in 60..69 -> println("D")
        else -> println("E")
    }
}

//使用for语句

fun forDemo() {
    for (i in 1..10) {
        println(i)
    }
    for (i in 10 downTo 1) {
        println(i)
    }
    for (i in 1..10 step 2) {
        println(i)
    }
    for (i in 1 downTo 10 step 2) {
        println(i)
    }
}